import Vuex from "vuex";
import Vue from "vue";
import axios from "@/axios"
// import { routes } from "@/router/index"
import promission from "./promission/promission"

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        login_tk: "",
        userProfile: "",
        // routes
    },
    mutations: {
        addcookie(state, payload) {
            state.login_tk = payload;
        },
        removeCookie(state) {
            state.login_tk = ""
        },
        removeuser(state) {
            state.userProfile = ""
        },
        updateUserProfile(state, data) {
            state.userProfile = data
        }
    },
    actions: {
        verUserProfile({ commit }, token) {
            commit;
            return new Promise((resolve, reject) => {
                axios.get("/userinfo/", {
                    headers: {
                        "token": token
                    }
                }).then(res => {
                    commit("updateUserProfile", res.data.data)
                    resolve(res.data)
                }).catch(err => {
                    reject(err.data)
                })
            })
        }
    },
    modules: {
        promission
    }
})

export default store;